using RestaurantFinder.Core.Models;

namespace RestaurantFinder.Core.Services;

/// <summary>
/// 搜索缓存服务接口
/// </summary>
public interface ISearchCacheService
{
    /// <summary>
    /// 获取缓存的搜索结果
    /// </summary>
    /// <param name="location">搜索位置</param>
    /// <param name="radiusInMeters">搜索半径</param>
    /// <param name="category">搜索类别</param>
    /// <returns>缓存的餐厅列表，如果没有缓存则返回null</returns>
    Task<List<Restaurant>?> GetCachedSearchResultAsync(Location location, int radiusInMeters, string? category = null);

    /// <summary>
    /// 缓存搜索结果
    /// </summary>
    /// <param name="location">搜索位置</param>
    /// <param name="radiusInMeters">搜索半径</param>
    /// <param name="restaurants">餐厅列表</param>
    /// <param name="category">搜索类别</param>
    Task SetCachedSearchResultAsync(Location location, int radiusInMeters, List<Restaurant> restaurants, string? category = null);

    /// <summary>
    /// 清除所有缓存
    /// </summary>
    Task ClearAllCacheAsync();

    /// <summary>
    /// 获取缓存统计信息
    /// </summary>
    /// <returns>缓存统计信息</returns>
    Task<CacheStatistics> GetCacheStatisticsAsync();
}

/// <summary>
/// 缓存统计信息
/// </summary>
public record CacheStatistics
{
    /// <summary>
    /// 缓存条目总数
    /// </summary>
    public int TotalEntries { get; init; }

    /// <summary>
    /// 缓存命中次数
    /// </summary>
    public long HitCount { get; init; }

    /// <summary>
    /// 缓存未命中次数
    /// </summary>
    public long MissCount { get; init; }

    /// <summary>
    /// 缓存命中率
    /// </summary>
    public double HitRate => (HitCount + MissCount) > 0 ? (double)HitCount / (HitCount + MissCount) : 0;

    /// <summary>
    /// 估计内存使用量（字节）
    /// </summary>
    public long EstimatedMemoryUsage { get; init; }
} 